home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 14 / Example 14.1 / mesh.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-30  |  1.8 KB  |  106 lines

  1. #ifndef _MESH
  2. #define _MESH
  3.  
  4. #include <d3dx9.h>
  5. #include <vector>
  6. #include "debug.h"
  7.  
  8. struct BBOX{
  9.     BBOX()
  10.     {
  11.         max = D3DXVECTOR3(-10000.0f, -10000.0f, -10000.0f);
  12.         min = D3DXVECTOR3(10000.0f, 10000.0f, 10000.0f);
  13.     }
  14.  
  15.     BBOX(D3DXVECTOR3 _max, D3DXVECTOR3 _min)
  16.     {
  17.         max = _max;
  18.         min = _min;
  19.     }
  20.  
  21.     D3DXVECTOR3 max, min;
  22. };
  23.  
  24. struct BSPHERE{
  25.     BSPHERE()
  26.     {
  27.         center = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
  28.         radius = 0.0f;
  29.     }
  30.  
  31.     BSPHERE(D3DXVECTOR3 _center, float _radius)
  32.     {
  33.         center = _center;
  34.         radius = _radius;
  35.     }
  36.  
  37.     D3DXVECTOR3 center;
  38.     float radius;
  39. };
  40.  
  41. struct ObjectVertex
  42. {
  43.     ObjectVertex(){}
  44.     ObjectVertex(D3DXVECTOR3 pos, D3DXVECTOR3 norm, float u, float v)
  45.     {
  46.         _pos = pos;
  47.         _norm = norm;
  48.         _u = u;
  49.         _v = v;
  50.     }
  51.  
  52.     D3DXVECTOR3 _pos, _norm;
  53.     float _u, _v;
  54.  
  55.     static const DWORD FVF;
  56. };
  57.  
  58. class MESH
  59. {
  60.     friend class OBJECT;
  61.     friend class MESHINSTANCE;
  62.     friend struct RAY;
  63.     public:
  64.  
  65.         MESH();
  66.         MESH(char fName[], IDirect3DDevice9* Dev);
  67.         ~MESH();
  68.         HRESULT Load(char fName[], IDirect3DDevice9* Dev);
  69.         void Render();
  70.         void Render(float prc);
  71.         void Release();
  72.  
  73.     private:
  74.  
  75.         IDirect3DDevice9 *m_pDevice;
  76.         ID3DXMesh *m_pMesh;
  77.         std::vector<IDirect3DTexture9*> m_textures;
  78.         std::vector<D3DMATERIAL9> m_materials;
  79.         D3DMATERIAL9 m_white;
  80. };
  81.  
  82. class MESHINSTANCE{
  83.     friend class OBJECT;
  84.     friend struct RAY;
  85.     public:
  86.         MESHINSTANCE();
  87.         MESHINSTANCE(MESH *meshPtr);
  88.         void Render();
  89.         void Render(float prc);
  90.  
  91.         void SetMesh(MESH *m)            {m_pMesh = m;}
  92.         void SetPosition(D3DXVECTOR3 p)    {m_pos = p;}
  93.         void SetRotation(D3DXVECTOR3 r)    {m_rot = r;}
  94.         void SetScale(D3DXVECTOR3 s)    {m_sca = s;}
  95.  
  96.         D3DXMATRIX GetWorldMatrix();
  97.         BBOX GetBoundingBox();
  98.         BSPHERE GetBoundingSphere();
  99.         
  100.         D3DXVECTOR3 m_pos, m_rot, m_sca;
  101.  
  102.     private:
  103.         MESH *m_pMesh;
  104. };
  105.  
  106. #endif